package common.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.Cookie;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;

//import dao.domain.UserCookie;

/**
 * æ–‡å­—åˆ—æƒ…å ±ãƒ»æ—¥ä»˜æƒ…å ±ç­‰ã�®æ–‡å­—ç·¨é›†Util
 *
 * @author s-araki
 * @version $Id: MiscUtils.java 1212 2010-08-30 05:16:30Z kenji.kodaka $
 **/
public class MiscUtils  {


	/** æ—¥ä»˜ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆ
	 * ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆæ–‡å­—åˆ—ã�®é•·ã�„é †ã�«è©•ä¾¡ã�•ã�›ã‚‹
	*/
	private static String[] DATE_FORMAT =
		{
			"yyyy/MM/dd HH:mm:ss",
			"yyyy-MM-dd HH:mm:ss",
			"yyyy/MM/dd HH:mm",
			"yyyy-MM-dd HH:mm",
			"yyyy/MM/dd",
			"yyyy-MM-dd",
			"yy/MM/dd",
			"yy-MM-dd",
			"yyyyMMdd",
			"yyMMdd",
			"MMdd",
			"dd/MM/yyyy"
		};


		/**
		 * ãƒ‘ã‚¿ãƒ¼ãƒ³ãƒžãƒƒãƒ�ã�®ãƒ†ã‚¹ãƒˆã‚’è¡Œã�„ã€�çµ�æžœã‚’ booleanã�§è¿”ã�™ã€‚
		 * @param String æ­£è¦�è¡¨ç�¾
		 * @param String è©•ä¾¡æ–‡å­—åˆ—
		 */
		public static boolean regMatch(String p, String s) {
			if(null == s || s.trim()==""){
				return false;
			}
			Pattern pattern = Pattern.compile(p);
			Matcher matcher = pattern.matcher(s);
			return matcher.matches();
		}

		/**
		* ãƒ‘ã‚¿ãƒ¼ãƒ³ãƒžãƒƒãƒ�ã�®ãƒ†ã‚¹ãƒˆã‚’è¡Œã�„ã€�çµ�æžœã‚’ booleanã�§è¿”ã�™ã€‚
		* å¤§æ–‡å­—å°�æ–‡å­—ã�®åŒºåˆ¥ã�¯è¡Œã‚�ã�ªã�„ã€‚
		* @param String æ­£è¦�è¡¨ç�¾
		* @param String è©•ä¾¡æ–‡å­—åˆ—
		**/
	 public static boolean regMatchIC(String p, String s) {
		 if(null == s){
				return false;
		}
		 Pattern pattern = Pattern.compile(p, Pattern.CASE_INSENSITIVE);
		 Matcher matcher = pattern.matcher(s);
		 return matcher.matches();
	 }

	 /**
	  * æ–‡å­—åˆ—ã‚’åˆ†å‰²ã�—ã�¦ã€�çµ�æžœã‚’ String[] ã�§è¿”ã�™ã€‚
	  * @param String æ­£è¦�è¡¨ç�¾
	  * @param String è©•ä¾¡æ–‡å­—åˆ—
	  **/
	 public static String[] regSplit(String p, String s) {
		 if(null == s){
				return null;
			}
		 Pattern pattern = Pattern.compile(p);
		 return pattern.split(s);
	 }

	 /**
	  * æ–‡å­—åˆ—ã‚’åˆ†å‰²ã�—ã�¦ã€�çµ�æžœã‚’ String[] ã�§è¿”ã�™ã€‚
	  * åˆ†å‰²æ•°ã�®ä¸Šé™�æŒ‡å®šã‚‚è¡Œã�†ã€‚
	  * @param String æ­£è¦�è¡¨ç�¾
	  * @param String è©•ä¾¡æ–‡å­—åˆ—
	  * @param String åˆ†å‰²ãƒªãƒŸãƒƒãƒˆ
	  */
	 public static String[] regSplit(String p, String s, int limit) {
		 Pattern pattern = Pattern.compile(p);
		 return pattern.split(s, limit);
	 }

	 /**
	  * æ–‡å­—åˆ—ã�®ç½®æ�›ã‚’è¡Œã�„ã€�ç½®æ�›ã�•ã‚Œã�Ÿæ–‡å­—åˆ—ã‚’è¿”ã�™ã€‚
	  * æœ€åˆ�ã�«ãƒžãƒƒãƒ�ã�—ã�Ÿã‚‚ã�®ã�—ã�‹ç½®æ�›ã�—ã�ªã�„
	  * @param String æ­£è¦�è¡¨ç�¾
	  * @param String ç½®æ�›æ–‡å­—
	  * @param String è©•ä¾¡æ–‡å­—åˆ—
	  */
	 public static String regReplaceFirst(String p, String r, String s) {
		 Pattern pattern = Pattern.compile(p);
		 Matcher matcher = pattern.matcher(s);
		 return matcher.replaceFirst(r);
	 }

	 /**
	  * æ–‡å­—åˆ—ã�®ç½®æ�›ã‚’è¡Œã�„ã€�ç½®æ�›ã�•ã‚Œã�Ÿæ–‡å­—åˆ—ã‚’è¿”ã�™ã€‚
	  * ãƒžãƒƒãƒ�ã�™ã‚‹ã‚‚ã�®ã�¯ã�™ã�¹ã�¦ç½®æ�›ã�™ã‚‹
	  * @param String æ­£è¦�è¡¨ç�¾
	  * @param String ç½®æ�›æ–‡å­—
	  * @param String è©•ä¾¡æ–‡å­—åˆ—
	  */
	 public static String regReplaceAll(String p, String r, String s) {
		 Pattern pattern = Pattern.compile(p);
		 Matcher matcher = pattern.matcher(s);
		 return matcher.replaceAll(r);
	 }

	 /**
	  * æ–‡å­—åˆ—ã�®ç½®æ�›ã‚’è¡Œã�„ã€�ç½®æ�›ã�•ã‚Œã�Ÿæ–‡å­—åˆ—ã‚’è¿”ã�™ã€‚
	  * ãƒžãƒƒãƒ�ã�™ã‚‹ã‚‚ã�®ã�¯ã�™ã�¹ã�¦ç½®æ�›ã�™ã‚‹
	  * matcher.find() ã‚’ç”¨ã�„ã�¦å®Ÿè£…ã�™ã‚‹ã€‚
	  * @param String æ­£è¦�è¡¨ç�¾
	  * @param String ç½®æ�›æ–‡å­—
	  * @param String è©•ä¾¡æ–‡å­—åˆ—
	  */
	 public static String regReplaceAll2(String p, String r, String s) {
		 Pattern pattern = Pattern.compile(p);
		 Matcher matcher = pattern.matcher(s);
		 StringBuffer sb = new StringBuffer();
		 while (matcher.find()) {
			 matcher.appendReplacement(sb, r);
		 }
		 matcher.appendTail(sb);
		 return sb.toString();
	 }

	/**
	 * æ—¥ä»˜ã‚’æ–‡å­—åž‹ã�«å¤‰æ�›ã�—ã�¾ã�™
	 *
	 * @param date ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆã�™ã‚‹æ—¥ä»˜
	 * @param format ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆæ›¸å¼�
	 * @return ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆå¾Œã�®æ–‡å­—åˆ—
	 */
	public static String formatDate(Date date, String format) {

		String rt;
		SimpleDateFormat df;
		try{

			if (date != null) {
				df = new SimpleDateFormat(format);
				rt = df.format(date);
			} else {
				rt = "";
			}
		}catch(Exception e){
			rt = "";
		}
		return rt;
	}

	/**
	 * æ–‡å­—åˆ—ã‚’æ—¥ä»˜åž‹ã�«ãƒ‘ãƒ¼ã‚¹ã�—ã�¾ã�™ã€‚
	 *
	 * @param str ãƒ‘ãƒ¼ã‚¹ã�™ã‚‹æ–‡å­—åˆ—
	 * @param format ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆæ›¸å¼�
	 * @return ãƒ‘ãƒ¼ã‚¹å¾Œã�®æ—¥ä»˜
	 * @exception ParseException
	 */
	public static Date parseDate(String str, String format)
		throws ParseException {
		return parseDate(str, format, true);
	}

	/**
	 * æ–‡å­—åˆ—æ—¥ä»˜ã�®ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆå¤‰æ�›
	 *
	 * @param str ãƒ‘ãƒ¼ã‚¹ã�™ã‚‹æ–‡å­—åˆ—
	 * @param format ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆæ›¸å¼�
	 * @return ãƒ‘ãƒ¼ã‚¹å¾Œã�®æ—¥ä»˜
	 * @exception ParseException
	 */
	public static String parseStrDate(String str, String format)
		throws ParseException {
		return formatDate(parseDate(str),format);
	}

	/**
	 * æ–‡å­—åˆ—ã‚’æ—¥ä»˜åž‹ã�«ãƒ‘ãƒ¼ã‚¹ã�—ã�¾ã�™ã€‚
	 *
	 * @param str ãƒ‘ãƒ¼ã‚¹ã�™ã‚‹æ–‡å­—åˆ—
	 * @param format ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆæ›¸å¼�
	 * @param lenient true ã�®å ´å�ˆã�¯åŽ³å¯†ã�§ã�¯ã�ªã�„è§£æž�
	 * @return ãƒ‘ãƒ¼ã‚¹å¾Œã�®æ—¥ä»˜
	 * @exception ParseException
	 */
	public static Date parseDate(String str, String format, boolean lenient)
		throws ParseException {
		//DbC
		if(str == null || format == null){
			throw new IllegalArgumentException("ç„¡åŠ¹ã�ªå¼•æ•°ã�§ã�™");
		}

		Date rt;
		SimpleDateFormat df;

		df = new SimpleDateFormat(format);
		df.setLenient(lenient);
		rt = df.parse(str);

		return rt;
	}

	/**
	 * æ–‡å­—åˆ—ã‚’æ—¥ä»˜åž‹ã�«ãƒ‘ãƒ¼ã‚¹ã�—ã�¾ã�™ã€‚
	 *
	 * @param str ãƒ‘ãƒ¼ã‚¹ã�™ã‚‹æ–‡å­—åˆ—
	 * @return ãƒ‘ãƒ¼ã‚¹å¾Œã�®æ—¥ä»˜
	 * @exception ParseException
	 */
	public static Date parseDate(String str)  {
		return parseDate(str, true);
	}

	/**
	 * æ–‡å­—åˆ—ã‚’æ—¥ä»˜åž‹ã�«ãƒ‘ãƒ¼ã‚¹ã�—ã�¾ã�™ã€‚<BR>
	 * ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆã�®è©•ä¾¡ã�¯å…ˆé ­ä¸€è‡´ã�§è©•ä¾¡ã�•ã‚Œã‚‹ç‚ºã€�<BR>
	 * ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆæ–‡å­—åˆ—ã�®ä¸¦ã�³é †ã‚’é•·ã�„é †ã�«å¤‰æ›´ã�—ã�Ÿ<BR>
	 *
	 * @param str ãƒ‘ãƒ¼ã‚¹ã�™ã‚‹æ–‡å­—åˆ—
	 * @param lenient true ã�®å ´å�ˆã�¯åŽ³å¯†ã�§ã�¯ã�ªã�„è§£æž�
	 * @return ãƒ‘ãƒ¼ã‚¹å¾Œã�®æ—¥ä»˜
	 * @exception ParseException
	 */
	public static Date parseDate(String str, boolean lenient)
		 {
		Date rt = null;
		try{
			//DbC
			if(str == null){
				return null;
				//throw new IllegalArgumentException("ç„¡åŠ¹ã�ªå¼•æ•°ã�§ã�™");
			}


			SimpleDateFormat df;
			int i;
			//ParseException exception = null;

			for (i = 0; i < DATE_FORMAT.length; i++) {
				try {
					df = new SimpleDateFormat(DATE_FORMAT[i]);
					df.setLenient(lenient);
					rt = df.parse(str);
					break;
				} catch (ParseException ex2) {
					//exception = ex2;
				}
			}

			if (rt == null) {
				df = new SimpleDateFormat();
				df.setLenient(lenient);
				rt = df.parse(str);
			}
		}catch (Exception e){
			return null;
		}
		return rt;
	}


	/**
	 * æ–‡å­—åˆ—æ—¥ä»˜ã‚’ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆå¤‰æ�›
	 *
	 * @param str å¤‰æ�›ã�™ã‚‹æ–‡å­—åˆ—
	 * @param format å¤‰æ�›å‰�ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆ
	 * @param format å¤‰æ�›å¾Œãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆ
	 * @return ãƒ‘ãƒ¼ã‚¹å¾Œã�®æ—¥ä»˜
	 * @exception ParseException
	 */
	public static String formatDString(String str, String before_format,String after_format)
		throws ParseException {

		if(str == null || before_format == null || after_format==null){
			return "";
		}

		Date d = parseDate(str, before_format);
		String s= formatDate(d,after_format);
		return s;
	}


	/**
	 * æ–‡å­—åˆ—ã‚’ Number ã�«å¤‰æ�›
	 *
	 * @param str å¤‰æ�›ã�™ã‚‹æ–‡å­—åˆ—
	 * @return å¤‰æ�›å¾Œã�® Number
	 * @exception ParseException
	 */
	public static Number parseNumber(String str) throws ParseException {
		Number rt;
		NumberFormat nf;

		// nullã‚‚ã�—ã��ã�¯""ã�®å ´å�ˆã�«ã�¯0ã‚’è¿”ã�™
		if (str == null || str.length() == 0) {
			return new Integer(0);
		}

		// ãƒ—ãƒ©ã‚¹è¨˜å�·ã�§å§‹ã�¾ã‚‹å ´å�ˆã�«ã�¯ã€�ãƒ—ãƒ©ã‚¹è¨˜å�·ã‚’å‰Šé™¤
		if (str.startsWith("+")) {
			str = str.substring(1);
		}

		// æ•°å€¤ã�®å¤‰æ�›
		nf = NumberFormat.getInstance();
		rt = nf.parse(str);

		return rt;
	}

	/**
	 * intã‚’æ–‡å­—åˆ—ã�«å¤‰æ�›
	 *
	 * @param int å¤‰æ�›ã�™ã‚‹æ•°å€¤
	 * @return å¤‰æ�›å¾Œã�® String
	 * @exception ParseException
	 */
	public static String parseStr(int i) {
		Integer _int = new Integer(i);
		return _int.toString();
	}


	/**
	 * æ–‡å­—åˆ—ã‚’ int ã�«å¤‰æ�›
	 *
	 * @param str å¤‰æ�›ã�™ã‚‹æ–‡å­—åˆ—
	 * @return å¤‰æ�›å¾Œã�® int
	 * @exception ParseException
	 */
	public static int parseInt(String str) throws ParseException {
		return parseNumber(str).intValue();
	}

	/**
	 * æ–‡å­—åˆ—ã‚’ long ã�«å¤‰æ�›
	 *
	 * @param str å¤‰æ�›ã�™ã‚‹æ–‡å­—åˆ—
	 * @return å¤‰æ�›å¾Œã�® long
	 * @exception ParseException
	 */
	public static long parseLong(String str) throws ParseException {
		return parseNumber(str).longValue();
	}

	/**
	 * æ–‡å­—åˆ—ã‚’ double ã�«å¤‰æ�›
	 *
	 * @param str å¤‰æ�›ã�™ã‚‹æ–‡å­—åˆ—
	 * @return å¤‰æ�›å¾Œã�® double
	 * @exception ParseException
	 */
	public static double parseDouble(String str) throws ParseException {
		return parseNumber(str).doubleValue();
	}


	/**
	 * æ–‡å­—åˆ—filenameã�‹ã‚‰æ‹¡å¼µå­�ã‚’å�–å¾—ã�—ã�¦è¿”ã�—ã�¾ã�™ã€‚æ‹¡å¼µå­�ã�Œç„¡ã�„å ´å�ˆã�¯
	 * ç©ºæ–‡å­—åˆ—ã‚’è¿”ã�—ã�¾ã�™ã€‚
	 */
	public static String getExt(String filename) {
	  String ext = "";
	  int pos = filename.lastIndexOf(".");
	  if (pos > 0) {
		ext = filename.substring(pos + 1, filename.length());
	  }
	  return ext;
	}


	/**
	 * æ—¥ä»˜åŒºåˆ‡ã‚Šæ–‡å­—ã�®é™¤åŽ»
	 *
	 * @return String è©•ä¾¡æ–‡å­—åˆ—
	 */
	public static String delDateSp(String s) {
		return regReplaceAll("/","",s);
	}

	/**
	 * æ•°å€¤åŒºåˆ‡ã‚Šæ–‡å­—ã�®é™¤åŽ»
	 *
	 * @return String è©•ä¾¡æ–‡å­—åˆ—
	 */
	public static String delAmtSp(String s) {
		if (s==null){
			return s;
		}else{
			return regReplaceAll(",","",s);
		}
	}

	/**
	 * ç”»é�¢è¡¨ç¤ºç”¨ã€€æ—¥ä»˜ãƒ•ã‚©ãƒ¼ãƒžãƒƒãƒˆå¤‰æ�›
	 *
	 * @return String è©•ä¾¡æ–‡å­—åˆ—
	 */
	public static String cnvDspDate(String s) {
		try{
			if (s==null){
				return s;
			}else{
				return formatDate(parseDate(s),"yyyy/MM/dd");
			}
		}catch (Exception e){
			return null;
		}
	}

	public static String cnvDspDate2(String s) {
		try{
			if (s==null){
				return s;
			}else{
				return formatDate(parseDate(s),"dd/MM/yyyy");
			}
		}catch (Exception e){
			return null;
		}
	}
	
	/**
		 * Stringåž‹ã�§æŒ‡å®šã�•ã‚Œã�Ÿæ•°å€¤ãƒ‡ãƒ¼ã‚¿ã�«ã€�å°�æ•°ç‚¹ä»¥ä¸‹ã�®æ¡�æ•°ã‚’ã��ã‚�ã�ˆã‚‹ã�Ÿã‚�ã�«0
		 * ã‚’è¿½åŠ ã�—ã�Ÿã‚Šã€�æ•´æ•°éƒ¨ã�«ã‚«ãƒ³ãƒžã‚’è¿½åŠ ã�—ã�Ÿã‚Šã�—ã�¾ã�™ã€‚
		 * @param src å‡¦ç�†å¯¾è±¡ã�®æ–‡å­—åˆ—(doubleåž‹ã�¨ã�—ã�¦èª�è­˜ã�§ã��ã‚‹ã�“ã�¨)
		 * @param scale å°�æ•°éƒ¨ã�®æ¡�æ•°
		 * @return
		 */
		public static String formatNumber(String src, int scale){
			if(src == null){
				return null;
			}
			src = src.trim();
			StringBuffer srcbuf = new StringBuffer(src);

			/* ã�¾ã�šæ•´æ•°éƒ¨ã€�å°�æ•°éƒ¨ã�®æ¡�æ•°ã‚’æ±‚ã‚�ã‚‹ */
			int seiketa, shouketa;
			int dotloc = src.indexOf('.');
			if(dotloc == -1){
				/* å°�æ•°ç‚¹ã�Œã�ªã�„ */
				seiketa = src.length();
				shouketa = 0;
			} else {
				/* ã��ã�®ä»–(å…ˆé ­ã�Œå°�æ•°ç‚¹ã�®å ´å�ˆã‚‚å�«ã‚€) */
				seiketa = dotloc;
				shouketa = src.length() - dotloc - 1;
			}

			/* shouketaã�Œscaleã�«æº€ã�Ÿã�ªã�„å ´å�ˆã€�å�³ã�«0ã‚’è¶³ã�™ */
			if(scale>0 && shouketa == 0){
				srcbuf.append('.');
			}
			for(int i=shouketa; i<scale; i++){
				srcbuf.append('0');
			}
			/* ã‚«ãƒ³ãƒžåŒºåˆ‡ã‚Š */
			if(seiketa > 3){
				int startIndex = seiketa % 3;
				if(startIndex == 0){
					startIndex = 3;
				}
				for(int i=startIndex; i<seiketa; i+=3){
					srcbuf.insert(i++, ',');
				}
			}
			/* å…ˆé ­ã�Œå°�æ•°ç‚¹ã�®å ´å�ˆã€�å…ˆé ­ã�«0ã‚’ã�¤ã�‘ã‚‹ */
			if(dotloc == 0){
				srcbuf.insert(0, '0');
			}
			return srcbuf.toString();
		}






		/**
		 * ã‚µã‚¤ãƒˆIDã�‹ã‚‰ãƒžãƒ¼ãƒ�ãƒ£ãƒ³ãƒˆIDã�®å�–å¾—
		 *
		 */
		public static String getSiteToMrch(String siteId){
			if (ValidateUtil.validateEmptyString(siteId)){
				return siteId;
			}
			//ã‚µã‚¤ãƒˆIDã�®å…ˆé ­6æ¡�ã‚’ãƒžãƒ¼ãƒ�ãƒ£ãƒ³ãƒˆIDã�¨ã�™ã‚‹
			if (siteId.length()>=6){
				return siteId.substring(0,6);
			}else{
				return siteId;
			}
		}

		/**
		 * æœˆã�Œï¼‘æ¡�ã�®å ´å�ˆã€�å‰�æ–¹ã�«"0"ã‚’ä»˜åŠ ã�™ã‚‹
		 *
		 * @param year
		 * @return
		 */
		public static String padMonth(String month){
			if (!ValidateUtil.validateEmptyString(month) && month.length()==1){
				month= "0"+month;
			}
			return month;
		}

		/**
		 * æœˆã�®å‰�æ–¹ã�®0ã‚’å‰Šé™¤ã�™ã‚‹
		 *
		 * @param year
		 * @return
		 */
		public static String trimMonth(String month){
			if (!ValidateUtil.validateEmptyString(month)){
				try{
					month =Integer.valueOf(month).toString();
				}catch (Exception e){

				}
			}
			return month;
		}

		/**
		 * å¹´ã�Œï¼’æ¡�ã�®å ´å�ˆã€�å‰�æ–¹ã�«"20"ã‚’ä»˜åŠ ã�™ã‚‹
		 *
		 * @param year
		 * @return
		 */
		public static String padYear(String year){
			if (!ValidateUtil.validateEmptyString(year)){
				if (year.length()==2){
					year= "20"+year;
				} else if (year.length()==1){
					year= "200"+year;
				}

			}
			return year;
		}

		/**
		 * å¹´ã�Œ2æ¡�ä»¥ä¸Šã�®å ´å�ˆã€�å¾Œæ–¹ã�®2æ¡�ã‚’è¿”ã�™
		 *
		 * @param year
		 * @return
		 */
		public static String trimYear(String year){
			if (!ValidateUtil.validateEmptyString(year)){
				if (year.length()>3){
					year = year.substring(year.length()-2,year.length());
				}else if (year.length()==1){
					year = "0"+year;
				}
			}
			return year;
		}

		/**
		 * ãƒ•ãƒ«ãƒ¡ãƒ¼ãƒ«ã‚¢ãƒ‰ãƒ¬ã‚¹ã�‹ã‚‰ãƒ‰ãƒ¡ã‚¤ãƒ³éƒ¨åˆ†ã‚’åˆ‡ã‚Šå�–ã‚‹
		 *
		 * @param mailaddr
		 * @return
		 */
		public static String splitMailDoamin(String mailaddr){
			String domain="";
			try{
				domain=mailaddr.split(Consts.MAIL_DMIN_SEPARATERE)[1];
			}catch (Exception e){
			}
			return domain;
		}
		/**
		 *
		 * @param arg1
		 * @param arg2
		 * @return
		 */
		public static String rightPad(String arg1,int arg2){
			return StringUtils.rightPad(arg1,arg2);
		}

		/**
		 *
		 * @param arg1
		 * @param arg2
		 * @param arg3
		 * @return
		 */
		public static String rightPad(String arg1,int arg2,String arg3){
			return StringUtils.rightPad(arg1,arg2,arg3);
		}

		/**
		 *
		 * @param arg1
		 * @param arg2
		 * @return
		 */
		public static String leftPad(String arg1,int arg2){
			return StringUtils.leftPad(arg1,arg2);
		}

		/**
		 *
		 * @param arg1
		 * @param arg2
		 * @param arg3
		 * @return
		 */
		public static String leftPad(String arg1,int arg2,String arg3){
			return StringUtils.leftPad(arg1,arg2,arg3);
		}

		/**
		 *
		 * @param arg1
		 * @param arg2
		 * @param arg3
		 * @return
		 */
		public static String replace(String arg1,String arg2,String arg3){
			return StringUtils.replace(arg1,arg2,arg3);
		}

		/**
		 *
		 * @param arg1
		 * @param arg2
		 * @param arg3
		 * @param agr4
		 * @return
		 */
		public static String replace(String arg1,String arg2,String arg3,int agr4){
			return StringUtils.replace(arg1,arg2,arg3,agr4);
		}

		/**
		 * å…ˆé ­ã‚’å°�æ–‡å­—ã�«å¤‰æ�›
		 *
		 * @param arg1
		 * @return
		 */
		public static String uncapitalise(String arg1){
			if(arg1==null || arg1.length() == 0) {
				return "";
			}
			return arg1.substring(0,1).toLowerCase() + arg1.substring(1);

		}

		/**
		 *
		 * @param arg1
		 * @param arg2
		 * @return
		 */
		public static String remove(String arg1,String arg2){
			return StringUtils.remove(arg1,arg2);
		}



		public static String getSetlStatString(Integer stat){
			if (stat==null){
				return "";
			}
			if (stat.intValue()==Consts.SETL_OK){
				return Consts.SETL_OK_STR;
			}else if (stat.intValue()==Consts.SETL_AUTH){
				return Consts.SETL_AUTH_STR;
			}else if (stat.intValue()==Consts.SETL_VOID){
				return Consts.SETL_VOID_STR;
			}else if (stat.intValue()==Consts.SETL_NG){
				return Consts.SETL_NG_STR;
			}else if (stat.intValue()==Consts.SETL_EXCEPTION){
				return Consts.SETL_EXCEPTION_STR;
			}else if (stat.intValue()==Consts.SETL_CB){
				return Consts.SETL_CB_STR;
			}else if (stat.intValue()==Consts.SETL_VOID_REQ){
				return Consts.SETL_VOID_REQ_STR;
			}else if (stat.intValue()==Consts.SETL_CAN_REQ){
				return Consts.SETL_CAN_REQ_STR;
			}else if (stat.intValue()==Consts.SETL_CANCEL){
				return Consts.SETL_CANCEL_STR;
			}else if (stat.intValue()==Consts.SETL_RETRIEVAL){
				return Consts.SETL_RETRIEVAL_STR;
			}else{
				return "";
			}
		}



	/**
		 * åˆ†å‰²å‡¦ç�†
		 * Stringã�®splitã�§ã�¯ã€�æœ€çµ‚è¡Œã�«delimiterã�Œã�‚ã�£ã�Ÿå ´å�ˆ
		 * åˆ†å‰²ã�•ã‚Œã�ªã�„ç‚º
		 *
		 * @param value
		 * @param delimiter
		 * @return
		 */
		public static String[] split(String value,String delimiter){

			    int count = 0;
			    int temi = 0;
			    int temj = value.indexOf(delimiter);

			    if (value.equals("")){
			      String[] values={""};
			      return values;
			    }
			    while (temj >= 0) {
			      count++;
			      temi = temj + delimiter.length();
			      temj = value.indexOf(delimiter, temi);
			    }

			    String[] values = new String[count+1];
			    int i = 0;
			    int j = value.indexOf(delimiter);
			    for (int h = 0; j >= 0; h++) {
			     values[h] = value.substring(i, j);
			      i = j + delimiter.length();
			      j = value.indexOf(delimiter, i);
			    }
			    values[count] = value.substring(i);
			    return values;
	}



		/**
		 * ãƒ¡ãƒ¼ãƒ«ã‚¢ãƒ‰ãƒ¬ã‚¹:@ä»¥é™�ã�¯ãƒžã‚¹ã‚­ãƒ³ã‚°
		 * @param telNo
		 * @param dispLen
		 * @return ä¾‹ï¼šã€€info@alij.ne.jp â†’ info@*********
		 * ä¾‹å¤–ã�®å ´å�ˆã€�""ã‚’è¿”ã�™
		 */
		public static String parseUserMail(String mail){

			try{

				//ç©ºã�‹ä¸�æ­£ã�ªãƒ¡ãƒ¼ãƒ«ã‚¢ãƒ‰ãƒ¬ã‚¹ã�‹ãƒ�ã‚§ãƒƒã‚¯
				if (ValidateUtil.validateEmptyString(mail) || !ValidateUtil.validateEmailStandard(mail)){
					return "";
				}else{

					int arobasPosition = mail.indexOf("@")+1;	//ã€�@ã€‘ã�®ä½�ç½®
					int nbLetters = mail.substring(arobasPosition).toString().length();	//æ–‡å­—åˆ—ã�®é•·ã�•

					//ã€�@ã€‘ã�‹ã‚‰ã€�*ã€‘ã‚’æŒ¿å…¥
					char[] stars = new char[nbLetters];
					Arrays.fill(stars, '*');

					return mail.substring(0,arobasPosition)+ new String(stars);
				}
			}catch(Exception e){
				return "";
			}
		}

		/**
		 * é›»è©±ç•ªå�·ï¼šçœŸã‚“ä¸­3æ¡�ã‚’é�žè¡¨ç¤º
		 * å¯¾å¿œç¯„å›²ï¼šã€€æ•°å­—+ãƒ�ã‚¤ãƒ•ãƒ³+ç©ºæ¬„
		 * ä¾‹ï¼š xxx-xxxx-xxxx, xxx-xxxxx xxxx, xxxxxxxxxxx,ã€€xxx xxxx xxxxã€€ã�ªã�©
		 * ä¾‹å¤–ã�®å ´å�ˆã€�""ã‚’è¿”ã�™
		 * @param mail
		 * @return
		 */
		public static String parseUserTel(String tel){

			try{
				String telephone = tel.trim().replace(" ", "");

				if (ValidateUtil.validateEmptyString(telephone)){
					return "";
				}else{

					//ãƒ�ã‚¤ãƒ•ãƒ³2ã�¤ä»¥ä¸Šã‚’æŒ�ã�£ã�¦ã�„ã‚‹ã�‹ç¢ºèª�
					boolean hasTwoHaifun = (telephone.indexOf("-")!=-1 && telephone.indexOf("-")!= telephone.lastIndexOf("-"))?true:false;

					//2ã�¤ã�®ãƒ�ã‚¤ãƒ•ãƒ³ã‚’å�«ã‚€é…�åˆ—ã�ªã‚‰ãƒ»ãƒ»ãƒ»
					if(hasTwoHaifun){
						int firstHaifun 	= telephone.indexOf("-",0);		//ä¸€ã�¤ç›®ã�®ãƒ�ã‚¤ãƒ•ãƒ³ä½�ç½®
						int secondHaifun 	= telephone.lastIndexOf("-");	//äºŒã�¤ç›®ã�®ãƒ�ã‚¤ãƒ•ãƒ³ä½�ç½®

						//1ã�¤ç›®ã�¨äºŒã�¤ç›®ã�®ãƒ�ã‚¤ãƒ•ãƒ³ã�®ä¸­ã�«ã€�*ã€‘ã‚’æŒ¿å…¥
						char[] stars = new char[(secondHaifun-firstHaifun-1)];
						Arrays.fill(stars, '*');

						return telephone.substring(0,firstHaifun+1) + new String(stars) + telephone.substring(secondHaifun);

					}else{

						//5æ¡�ä»¥ä¸Šã�®ã‚‚ã�ªã‚‰ã€�ãƒžã‚¹ã‚­ãƒ³ã‚°
						if(telephone.length()>=5){
							int middle = (telephone.length())/2;	//æ–‡å­—åˆ—ã�®çœŸã‚“ä¸­ã�®Indexï¼ˆå››æ�¨äº”å…¥ï¼‰
							return telephone.substring(0,(middle-1)) + "***" + telephone.substring(middle+2);
						}else{
							return telephone;
						}
					}
				}

			}catch(Exception e){
				return "";
			}
		}
		/**
		 * @author thuna
		 * @Description: parse a such date to format date yyyy/mm/dd
		 * @param date
		 * @return String
		 */
		public static final String parseToFormatString(Date date){
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
			
			return simpleDateFormat.format(calendar.getTime());
		}
		
		/**
		 * @author thuna
		 * @Description: parse string to date with format yyyy/MM/dd
		 * @param date
		 * @return
		 */
		public static final Date parseFromFormatString(String date){
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
			try {
				return simpleDateFormat.parse(date);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}
		
		public static final Date parseFromFormatString2(String date){
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
			try {
				return simpleDateFormat.parse(date);
			} catch (ParseException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}
		/**
		 * @author thuna
		 * @Description: encrypt a input string by md5 algorithm
		 * @param plainText
		 * @return String
		 */
		public static final String encryptedMd5(String plainText){
			if(plainText != null){
				MessageDigest m;
				try {
					m = MessageDigest.getInstance("MD5");
					m.reset();
					m.update(plainText.getBytes());
					byte[] digest = m.digest();
					BigInteger bigInt = new BigInteger(1, digest);
					String hashText = bigInt.toString(16);
	//				if(hashText.length() > 30){
	//					hashText = hashText.substring(0, 30);
	//				}
					return hashText;
				} catch (NoSuchAlgorithmException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return null;
		}
		/**
		 * @author thuna
		 * @Description: add user name and password to cookie
		 * @param userId
		 * @param passWord
		 */
		public static final void addUserCookie(String userId, String passWord){
			Cookie[] cookies = ServletActionContext.getRequest().getCookies();
        	Cookie userCookie = null;
        	Cookie passCookie = null;
	        for(int i = 0; i < cookies.length; i++) {
	            if (cookies[i].getName().equals("UserId")) {
	            	userCookie = cookies[i];
	            }else if(cookies[i].getName().equals("PassWord")){
	            	passCookie = cookies[i];
	            }
	            if(userCookie != null && passCookie != null){
	            	break;
	            }
	        }  

	        // Add user name to cookie
	        if (userCookie == null) {
	            userCookie = new Cookie("UserId", userId);
	        }
            userCookie.setValue(userId);
            ServletActionContext.getResponse().addCookie(userCookie);
            // Add password to cookie
	        if (passCookie == null) {
	            passCookie = new Cookie("PassWord", passWord);
	        }
	        passCookie.setValue(passWord);
	        ServletActionContext.getResponse().addCookie(passCookie);
		}
		/**
		 * @author thuna
		 * @Description: delete user from cookie
		 */
		public static final void deleteUserCookie(){
			int count = 0;
			Cookie[] cookies = ServletActionContext.getRequest().getCookies();
	        for(int i = 0; i < cookies.length; i++) {
	            if (cookies[i].getName().equals("UserId")) {
	            	cookies[i].setValue("");
	            	count++;
	            	ServletActionContext.getResponse().addCookie(cookies[i]);
	            }else if(cookies[i].getName().equals("PassWord")){
	            	cookies[i].setValue("");
	            	count++;
	            	ServletActionContext.getResponse().addCookie(cookies[i]);
	            }
	            if(count >= 2){
	            	break;
	            }
	        }  
		}
		/*
		public static final UserCookie isSavedUserCookie(){
			UserCookie userCookie = new UserCookie();
			Cookie[] cookies = ServletActionContext.getRequest().getCookies();
	        for(int i = 0; i < cookies.length; i++) {
	        	if(cookies[i].getValue() != null && cookies[i].getValue().length() > 0){
	        		if(cookies[i].getName().equals("UserId")){
	        			userCookie.setSaved(true);
	        			userCookie.setUserName(cookies[i].getValue());
	        		}else if(cookies[i].getName().equals("PassWord")){
	        			userCookie.setSaved(true);
	        			userCookie.setPassWord(cookies[i].getValue());
	        			if(userCookie.getUserName().length() > 0){
	        				break;
	        			}
	        		}
	        	}
	        }
	        return userCookie;
		}*/
		
		/**
		 * @author LanCT
		 * @param int lenght
		 * @return String random password
		 * @description get random n char password
		 */
		private static final String dCase = "abcdefghijklmnopqrstuvwxyz";
		private static final String uCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		private static final String intChar = "0123456789";
	    public static String returnRandomPassword(int lenght) {
	    	String pass = "";
			Random r = new Random();
	    	Random r1 = new Random();
	        while (pass.length () != lenght-2){
	            int rPick = r.nextInt(2);
	            int spot;
	            if (rPick == 0){
	                spot = r1.nextInt(25);
	                pass += dCase.charAt(spot);
	            } else{
	                spot = r1.nextInt (25);
	                pass += uCase.charAt(spot);
	            }
	        }
	        for(int i=0; i < 2; i++){
	        	int spot;
	        	spot = r1.nextInt (9);
	        	pass += intChar.charAt (spot);
	        }
	        return pass;
	    }
}
